import { ApiResponse, Channel } from '@/types/data'
import { RootThunkAction } from '@/types/store'
import request from '@/utils/request'

export const getUserChannel = (): RootThunkAction => {
  return async (dispatch, getState) => {
    const res = await request.get<ApiResponse<{ channels: Channel[] }>>(
      '/channels'
    )
    dispatch({
      type: 'home/saveUserChannels',
      payload: res.data.data.channels
    })
  }
}
